#include "mainwindow.h"
#include <QApplication>
#include <QTextCodec>

#include "keyboard.h"

QUdpSocket *udpSocket;

#define _TIME_ qPrintable(QDateTime::currentDateTime().toString("hh:mm:ss"))

static void networkLog(QtMsgType type, const char* msg)
{
   QString qstrTest;

   switch (type)
   {
       case QtDebugMsg:
               qstrTest = QString("%1: %2").arg(_TIME_ , msg);
               break;
       case QtWarningMsg:
               qstrTest = QString("%1: %2").arg(_TIME_ , msg);
               break;
       case QtCriticalMsg:
               qstrTest = QString("%1: %2").arg(_TIME_ , msg);
               break;
       case QtFatalMsg:
               qstrTest = QString("%1: %2").arg(_TIME_ , msg);
               exit(0);
   }

   QHostAddress hostaddr;
   hostaddr.setAddress( "192.168.1.223" );
   udpSocket->writeDatagram( qstrTest.toAscii(), hostaddr, 12345 );
}


int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    udpSocket = new QUdpSocket();

    //qInstallMsgHandler(networkLog);

    QTextCodec *codec = QTextCodec::codecForName("UTF-8");
    QTextCodec::setCodecForLocale(codec);
    QTextCodec::setCodecForCStrings(codec);
    QTextCodec::setCodecForTr(codec);

    QFile file(":/image/main.css");
    file.open(QFile::ReadOnly);
    QString qss = QLatin1String(file.readAll());
    qApp->setStyleSheet(qss);

    CKeyBoard *pInputContext = new CKeyBoard();
    a.setInputContext(pInputContext);

    MainWindow w;
    w.show();

    return a.exec();
}
